<?php

namespace app\shopapi\controller;



use app\common\controller\Shopapi;
use app\shopapi\model\ShopAuthGroup;



/**
 * 角色接口
 */
class Authgroup extends Shopapi
{
    //protected $noNeedLogin = [''];
    protected $noNeedRight = '*';

    public function create()
    {
        $group_model = new ShopAuthGroup();
        $data = [
            'shop_id'=>$this->shopauth->shop_id,
            'name'=>input('name',''),
            'permissions'=>input('permissions',0)
        ];
        if (empty($data['name']))$this->error('请输入角色名称');

        $res = $group_model->save($data);
        if ($res){
            $this->success('添加成功');
        } else {
            $this->error('添加失败');
        }
    }

    public function edit()
    {
        $id = input('id',0);
        $permissions = input('permissions',0);
        $name = input('name','');
        $detail = ShopAuthGroup::get($id);
        $detail->permissions = $permissions;
        $detail->setAttr('name',$name);
        $res = $detail->save();
        if ($res){
            $this->success('编辑成功');
        } else {
            $this->error('编辑失败');
        }
    }

    public function del()
    {
        $id = input('id',0);
        $detail = ShopAuthGroup::get($id);
        if ($detail->delete()){
            $this->success('删除成功');
        } else {
            $this->error('删除失败');
        }
    }

    public function lists()
    {
        $list = ShopAuthGroup::where(['shop_id'=>$this->shopauth->shop_id])
            ->select();
        $this->success('',$list);
    }
}